#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5,N=1e6+5;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--){
        int n,a[maxn],flag[N];
        bool k[N];
        long long ans=0;
        memset(flag,0,sizeof(flag));
        memset(k,0,sizeof(k));
        scanf("%d",&n);
        for(int i=1;i<=n;++i){
            scanf("%d",&a[i]);
            flag[a[i]]++;
        }
        for(int i=1;i<=n;++i){
            if(flag[a[i]]<=1) continue;
            if(!k[a[i]]){
                ans+=a[i];
                k[a[i]]=1;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}
